package io.hilo.example.biz01.service;

import org.hilo.boot.core.BaseMsg;
import org.hilo.boot.core.exception.AppException;
import org.jretty.util.NestedRuntimeException;
import org.springframework.stereotype.Service;


/**
 * Service Demo
 * 业务逻辑处理
 * 
 * @author xxxx
 * @since 2023-10-12
 */
@Service
public class DemoPlainService {

    public Integer add(Integer a, Integer b) {
        // -- 正式开始
        if (a == 0) {
            // 测试 抛出jdk异常
            System.err.println(b / a);
        }
        if (b == 0) {
            // 测试 抛出nested异常
            testMethod(a, b);
        }
        if (b < 1) {
            // 测试 抛出app异常
            throw new AppException(BaseMsg.PARAM_INVALID, b);
        }
        return a + b;
    }
    
    protected void testMethod(int a, int b) {
        try {
            System.err.println(a / b);
        } catch (Exception e) {
            throw new NestedRuntimeException(e);
        }
    }

}
